import Vue from 'vue'
import VueRouter from 'vue-router'

// 防止当前路由连续点击时报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: () => import('@/views/login'),
  },
  {
    path: '/',
    component: () => import('@/views/layout'),
    redirect: 'home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home'),
        meta: {
          // 属性1:'属性值'
          title: '首页',
          icon: 's-home'
        }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/goods'),
        meta: {
          title: '商品',
          icon: 's-goods'
        }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/order'),
        meta: {
          title: '订单',
          icon: 'present'
        }
      },
      {
        path: 'actives',
        name: 'actives',
        component: () => import('@/views/actives'),
        meta: {
          title: '活动',
          icon: 's-flag'
        }
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

export default router
